<template>
  <a-form-model layout="horizontal" ref="ruleForm" :rules="rules" :model="model" v-bind="formItemLayout">
    <z-form-item :rules="rules" :datas="fieldArr" :form="model" :gutter="0" @change="getChange"/>
  </a-form-model>
</template>

<script>
var phoneValidator = (rule, value, callback) => {
  if (!value || new RegExp(/^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/).test(value)) {
    callback()
  } else {
    callback('请输入正确的申请人电话')
  }
}
export default {
  props: ['current', 'controlPersonType', 'value'],
  data() {
    return {
      formItemLayout: {
        labelCol: { span: 6 },
        wrapperCol: { span: 13 },
      },
      model: {},
      fieldArr: [
        {label: '姓名', prop: 'realName', tagType: 'input',  disabled: true},
        {label: '户籍地址', prop: 'houseLevels', tagType: 'linkage-area',  disabled: true},
        {label: '户籍地详址', prop: 'householdAddress', tagType: 'input',  disabled: true},
        {label: '户籍地派出所', prop: 'householdPoliceStation', tagType: 'input',  disabled: true},
        {label: '户籍地专干姓名', prop: 'registerManagerName', tagType: 'input',  disabled: true},
        {label: '专干联系电话', prop: 'registerManagerPhone', tagType: 'input',  disabled: true},
        {label: '户籍地民警姓名', prop: 'policeName', tagType: 'input',  disabled: true},
        {label: '民警联系电话', prop: 'policePhone', tagType: 'input',  disabled: true},
        {label: '居住地详址', prop: 'currentAddress', tagType: 'input',  disabled: true},
        {label: '居住地执行社区', prop: 'currentLevels', tagType: 'linkage-area',  disabled: true},
        {label: '居住地派出所', prop: 'currentPoliceStation', tagType: 'input',  disabled: true},
        {label: '籍贯', prop: 'country', tagType: 'dict-select', dictCode:'country', disabled: false},
        {label: '涉网信息情况', prop: 'networkInfoSituation', tagType: 'textarea'},
        {label: '当前管控状态', prop: 'currentControlStatus', tagType: 'dict-select', dictCode:'current_control_status'},
        {label: '申请异地管控时间', prop: 'applyControlDate', tagType: 'date-picker', format: 'YYYY-MM-DD'},
        {label: '申请异地管控原因', prop: 'applyControlReason', tagType: 'textarea'},
        {label: '申请人姓名', prop: 'applyName', tagType: 'input'},
        {label: '申请人电话', prop: 'applyPhone', tagType: 'input'},
        {label: '证明材料', prop: 'file', tagType: 'upload-file', fileDescribe: '上传撤销异地管控的理由依据或者居住地住址、就业、就读等相关证明材料附件；上传社戒社康人员信息登记表等信息；', fileFormat: '.doc,.docx,.xls,.xlsx,.pdf,.jpg,.jpeg,.png'},
      ],
      rules: {
        // currentTowns: [ { required: true, message: '请选择', trigger: 'change' }, ],
        currentControlStatus: [ { required: true, message: '请选择', trigger: 'change' }, ],
        applyControlDate: [ { required: true, message: '请选择', trigger: 'change' }, ],
        applyControlReason: [ { required: true, message: '请输入', trigger: 'change' }, ],
        applyName: [ { required: true, message: '请输入', trigger: 'change' }, ],
        applyPhone: [
          { required: true, message: '请输入', trigger: 'change' },
          { validator: phoneValidator }
        ],
        file: [ { required: true, message: '请选择', trigger: 'change' }, ],
      },
    }
  },
  computed: {
    getValue() {
      let value = this.value ? this.value : {}
      return value
    }
  },
  watch: {
    getValue: {
      immediate: true,
      deep: true,
      handler(val) {
        this.model = Object.assign({}, this.model, val)
        this.$set(this.model, 'applyType', 1) //	申请类型 1、转入 2、转出 （转出outside_person_id关联sjsk_perosn的id）
      }
    },
    // model:{
    //   immediate: true,
    //   deep: true,
    //   handler(val) {
    //     this.$emit('change', this.current, val)
    //   }
    // }
  },
  methods: {
    getChange(prop, value) {
      if(prop==='currentTowns') {
        let data = value? value.filter(item=>{ return item }): []
        this.$set(this.model, 'currentTown', data.toString())
      }
    },
  }
}
</script>

<style scoped lang="less"></style>
